<?php

use console\db\Migration;
use yii\db\Query;
use yii\db\Expression;
use yii\helpers\Console;
use yii\helpers\ArrayHelper;
use yii\base\Exception;

/**
 * 更新用户等级
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300200_100020_t_user_trend_level extends Migration {

    /**
     * @inheritdoc
     */
    public $tableName = '{{%user_trend}}';

    /**
     * @inheritdoc
     */
    public function safeUp() {

        $conditions = [
            ['and', ['>=', 'experience', 0], ['<=', 'experience', 100]],
            ['and', ['>=', 'experience', 101], ['<=', 'experience', 500]],
            ['and', ['>=', 'experience', 501], ['<=', 'experience', 1200]],
            ['and', ['>=', 'experience', 1201], ['<=', 'experience', 2500]],
            ['and', ['>=', 'experience', 2501], ['<=', 'experience', 5000]],
            ['and', ['>=', 'experience', 5001], ['<=', 'experience', 8000]],
            ['and', ['>=', 'experience', 8001], ['<=', 'experience', 12000]],
            ['and', ['>=', 'experience', 12001], ['<=', 'experience', 20000]],
            ['and', ['>=', 'experience', 20001], ['<=', 'experience', 30000]],
            ['and', ['>=', 'experience', 30001], ['<=', 'experience', 50000]],
            ['and', ['>=', 'experience', 50001], ['<=', 'experience', 80000]],
            ['and', ['>=', 'experience', 80001], ['<=', 'experience', 120000]],
            ['and', ['>=', 'experience', 120001], ['<=', 'experience', 200000]],
            ['and', ['>=', 'experience', 200001], ['<=', 'experience', 300000]],
            ['and', ['>=', 'experience', 300001], ['<=', 'experience', 500000]],
            ['and', ['>=', 'experience', 500001], ['<=', 'experience', 800000]],
            ['and', ['>=', 'experience', 800001], ['<=', 'experience', 1200000]],
            ['and', ['>=', 'experience', 1200001], ['<=', 'experience', 1700000]],
            ['and', ['>=', 'experience', 1700001], ['<=', 'experience', 2100000]],
            ['and', ['>=', 'experience', 2100001], ['<=', 'experience', 3000000]],
            ['>', 'experience', 3000000]
        ];

        foreach ($conditions as $key => $where) {
            $this->update($this->tableName, [
                'level_id' => $key + 1
            ], $where);
        }
    }

}
